package com.yuanwushe.blue.video;

import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class VideoActivity extends AppCompatActivity {
    private VideoView VideoView;
    private int LastPalyedTime = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getSupportActionBar().hide();
        init();
    }

    private void init()
    {
        Uri uri = getIntent().getData();
        String path = uri.getPath();
        VideoView = findViewById(R.id.video_view);
        VideoView.setVideoPath(path);

        MediaController mediaController = new MediaController(this);
        VideoView.setMediaController(mediaController);
        VideoView.start();
    }

    @Override
    protected void onPause() {
        super.onPause();
        VideoView.pause();
        LastPalyedTime = VideoView.getCurrentPosition();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        VideoView.start();
        if (LastPalyedTime > 0) {
            VideoView.seekTo(LastPalyedTime);
        }
    }
}
